package cn.sdhuijin.healthexam.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import cn.sdhuijin.healthexam.ExitApplication;
import cn.sdhuijin.healthexam.R;
import cn.sdhuijin.healthexam.control.AbstractControlActivity;
import cn.sdhuijin.healthexam.util.Constants;

/**
 * 健康体检录入-第二页
 * 
 * @author houyuchun
 * 
 */
public class HealthExamSecondActivity extends AbstractControlActivity implements
		OnClickListener {
	private String createDate;
	// 饮食习惯选项
	private int[] checkYinshiIds = { R.id.check_ysxg_hunshi,
			R.id.check_ysxg_hunsu, R.id.check_ysxg_sushi,
			R.id.check_ysxg_shiyan, R.id.check_ysxg_shitang,
			R.id.check_ysxg_shiyou };

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_health_exam_second);
		ExitApplication.getInstance().addActivity(this);

		Intent intent = getIntent();
		Bundle bundle = intent.getBundleExtra("bundle");
		if (bundle != null) {
			createDate = bundle.getString("createDate");
		}
		setCurrentEditUserName(createDate);

		addRadioGroupView(R.id.rad_jkztzwpg, "健康状态");
		addRadioGroupView(R.id.rad_shzlnlzwpg, "生活自理能力");
		addRadioGroupView(R.id.rad_renzhigongneng, "认知功能");

		addEditTextView(R.id.edt_jyzljcdf, "简易智力状态检查评分");
		addEditTextView(R.id.edt_yypfjcdf, "老人年抑郁检查评分");

		addRadioGroupView(R.id.rad_qingganzhuangtai, "情感状态");
		addRadioGroupView(R.id.rad_duanlianpinlv, "锻炼频率");

		addEditTextView(R.id.edt_meiciduanliansj, "每次锻炼时间");
		addEditTextView(R.id.edt_jianchidlsj, "坚持锻炼时间");
		addEditTextView(R.id.edt_duanlianfangshi, "锻炼方式");

		addCheckBoxView(checkYinshiIds, "饮食习惯");
		// Properties文件路径
		controlManager.setPropertiesPath(Constants.PROPERTIES_PATH + createDate
				+ ".txt");
		Log.i(HealthExamFirstActivity.class.getSimpleName(), "文件路径： "
				+ Constants.PROPERTIES_PATH + createDate + ".txt");
		controlManager.toControl();

		this.setButtonListener(this, R.id.btn_next, R.id.btn_previous);
	}

	/**
	 * 按钮点击处理事件
	 */
	@Override
	public void onClick(View arg0) {
		Intent intent = new Intent();
		Bundle bundle = new Bundle();
		// 获取点击按钮
		int id = (Integer) arg0.getId();
		switch (id) {
		case R.id.btn_previous:
			controlManager.toProperties();
			bundle.putString("createDate", createDate);
			// 创建日期
			intent.putExtra("bundle", bundle);
			// 前一页按钮
			intent.setClass(this, HealthExamFirstActivity.class);
			startActivity(intent);
			this.finish();
			break;
		case R.id.btn_next:
			controlManager.toProperties();
			bundle.putString("createDate", createDate);
			// 创建日期
			intent.putExtra("bundle", bundle);
			intent.setClass(this, HealthExamThirdActivity.class);
			startActivity(intent);
			this.finish();
			break;
		default:
			break;
		}
	}
}
